﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;

using Joyintech.Common;
using Joyintech.BLL.inpiao365;
using Joyintech.Model.inpiao365;
using System.Data;

namespace Joyintech.Admin.inpiao365.general.system.Interface
{
    public partial class index : System.Web.UI.Page
    {
       protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //判断是否为修改操作
                if (DNTRequest.GetQueryString("Interface_Id") != "")
                {
                    DataBindForm();
                }
                else
                {
                    MessageBox.ShowAndRedirect(this, "非法操作！", "about:blank");
                }
            }
        }

        #region 绑定表单数据

        /// <summary>
        /// 绑定表单数据
        /// </summary>
        private void DataBindForm()
        {
            DataSet ds = new DataSet();

            ds = new systemInterface_BLL().GetList("InterfaceId=" + DNTRequest.GetQueryString("Interface_Id"));

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                Joyintech.WebControls.HFPanel.BindForm(this.HFPanel1, ds.Tables[0].DefaultView);
            }
        }

        #endregion

        #region 保存表单数据

        /// <summary>
        /// 保存表单数据到表systemInterface
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            systemInterface model = new systemInterface();

            string strError = string.Empty;

            strError = Joyintech.WebControls.HFPanel.FormCheck(this.HFPanel1, model);

            if (!strError.Equals(""))
            {
                MessageBox.Show(this, strError);
                return;
            }

            Joyintech.WebControls.HFPanel.GetForm(this.HFPanel1, model);

            //操作结果
            int dataResult = 0;

            if (DNTRequest.GetQueryString("Interface_Id") != "")
            {
                model.InterfaceId = Convert.ToInt32(DNTRequest.GetQueryString("Interface_Id").ToString());

                dataResult = new systemInterface_BLL().Update(model);
            }

            if (dataResult == 1)
            {
                //更新Global静态变量
                systemUser_BLL.GetInstance().StoreObject("Interface", new systemInterface_BLL().GetModel(1));

                MessageBox.Show(this, "保存成功，刷新页面即可看到效果！");
            }
            else
            {
                MessageBox.Show(this, "保存时发生异常，请重试！");                
            }
        }

        #endregion
    }
}